<template>
  <div>
    <div slot="header" class="clearfix">
      <span style="float: left; padding: 3px 0">USB白名单监控策略列表</span>
      <el-button style="float: right; padding: 3px 0" type="text" @click="Refresh">刷新</el-button>
    </div>
    <com-table :tableData="tableData" url="3in1/policy/usb_dev" keyName="app" :has-data="hasData"
      :table-head-list="tableHeadList" :total-count="totalCount" :page-num="pageNum" :page-size="pageSize"
      :page-sizes="pageSizes" :table-loading="loading" :table-height="tableHeight" :is-show-select="false"
      :page-show="false" :handle-show="true" :merge-flag="false" :modifys="true" :baddtsd="false"
      @setSearchHeight="setTableHeight" @openDialog="openDialog" ref="comTable" :deletebtn="false" :ifShowOnline="true"
      addOnline="状态" @isOnline="isOnline">

    </com-table>

  </div>
</template>
<script>
import ComTable from "../../components/table/comTable";
export default {
  name: "mabDevice",
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      pageSizes: [5, 10, 20, 100],
      totalCount: 0,
      tableData: [], // 表格数据
      tableHeight: "", // 表格高度
      hasData: true,
      loading: false, // 数据加载状态遮罩
      checkList: [],
      tableHeadList: [
        { columnComment: "策略名称", columnName: "name", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
        // {
        //   columnComment: "状态", columnName: "state", typeCollection: "stateEnum", colDisabled: false, colHidden: true, colSearch: true, colSort: false,
        // },
        { columnComment: "创建人", columnName: "creator", colDisabled: false, colHidden: true, colSearch: true, colSort: false, },
        { columnComment: "创建时间", columnName: "enableTime", colDisabled: false, colHidden: false, colSearch: true, colSort: false, },
      ],
      dialogControl: false,
    };
  },
  components: {
    ComTable,
  },
  created() {
    this.setTableHeight()
    this.getTableData()
  },
  methods: {
    Refresh() {
      this.getTableData()
    },
    getTableData() {
      this.$get('3in1/policy/usb_dev').then(jsonData => {
        console.log(jsonData, "sss");
        this.tableData = jsonData.data.data
      })
    },
    //新建与修改
    openDialog(type, row) {
      console.log('aaa');
      this.$router.push({
        path: '/USBform',
        name: 'USBform',
        params: row
      });
    },
    dialogClosed() { },
    addTerminal() {
      this.dialogControl = false;
      this.$message({
        type: "success",
        message: "新增成功！",
      });
    },
    modifyTerminal() {
      this.dialogControl = false;
      this.$message({
        type: "success",
        message: "修改成功！",
      });
    },
    delegods() {
      this.$confirm("确认删除？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功！",
          });
        })
        .catch((_) => { });
    },
    setTableHeight() {
      let clientHeiht =
        window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 110;
    },
    isOnline(val, row) {
      console.log(row);
      let params = {
        Root: {
          Policy: row.Root,
        },
        creator: sessionStorage.getItem('userName'),
        enableTime: "",
        name: row.Root.name,
        state: val,
      }
      this.$postForJson('3in1/policy/usb_dev', { policy: params }).then(res => {
        let { data } = res
        if (data.errorcode == '0') {
          this.$message({
            type: "success",
            message: "提交成功！",
          });
          this.getTableData()
        }
      })
    }
  },
};
</script>

<style scoped>
.el-checkbox-group {
  display: flex;
  flex-direction: column;
}
.el-select {
  width: 100%;
}
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
</style>